<template>
	<view class="content">
		<!-- 搜索 -->
		<uni-search-bar class="search" :radius="100" @confirm="search"></uni-search-bar>
		<!-- 头部轮播 -->
		<view class="banner">
			<swiper class="swiper" :indicator-dots="true" :autoplay="true" :interval="3000" :duration="1000">
				<swiper-item 
				class="swiper-item" 
				v-for="(item, index) in carouselList" :key="index"><image 
				:src="item.image" 
				@click="navToDetailPage(item)"
				/></swiper-item>
			</swiper>
		</view>
		<!-- 分类 -->
		<view class="cate-section">
			<view class="cate-item">
				<image src="/static/temp/c3.png"></image>
				<text>环球美食</text>
			</view>
			<view class="cate-item">
				<image src="/static/temp/c5.png"></image>
				<text>个护美妆</text>
			</view>
			<view class="cate-item">
				<image src="/static/temp/c6.png"></image>
				<text>营养保健</text>
			</view>
			<view class="cate-item">
				<image src="/static/temp/c7.png"></image>
				<text>家居厨卫</text>
			</view>
			<view class="cate-item">
				<image src="/static/temp/c8.png"></image>
				<text>速食生鲜</text>
			</view>
		</view>
		<!-- 分类 -->
		<view class="ad-1"><image src="/static/temp/ad1.jpg" mode="scaleToFill"></image></view>
		<!-- 秒杀楼层 -->
		<view class="seckill-section m-t">
			<view class="s-header">
				<image class="s-img" src="/static/temp/secskill-img.jpg" mode="widthFix"></image>
				<text class="tip">8点场</text>
				<text class="hour timer">07</text>
				<text class="minute timer">13</text>
				<text class="second timer">55</text>
			</view>
			<scroll-view class="floor-list" scroll-x>
				<view class="scoll-wrapper">
					<view v-for="(item, index) in goodsList" :key="index" class="floor-item" @click="navToDetailPage(item)">
						<image :src="item.image" mode="aspectFill"></image>
						<text class="title clamp">{{ item.title }}</text>
						<text class="price">￥{{ item.price }}</text>
					</view>
				</view>
			</scroll-view>
		</view>
		<!-- 团购楼层 -->
		<view class="f-header">
			<image src="/static/temp/h1.png"></image>
			<view class="tit-box">
				<text class="tit">精品团购</text>
				<text class="tit2">大牌精选</text>
			</view>
		</view>

		<view class="group-section">
			<swiper class="g-swiper" :duration="500">
				<swiper-item class="g-swiper-item" v-for="(item, index) in goodsList" :key="index" v-if="index % 2 === 0">
					<view class="g-item left"  @click="navToDetailPage(item)">
						<image :src="item.image" mode="aspectFill"></image>
						<view class="t-box">
							<text class="title clamp">{{ item.title1 }}</text>
							<view class="price-box">
								<text class="price">￥{{ item.price }}</text>
								<text class="m-price">￥188</text>
							</view>

							<view class="pro-box">
								<view class="progress-box"><progress percent="65" activeColor="#fa436a" active stroke-width="6" /></view>
								<text>6人成团</text>
							</view>
						</view>
					</view>
					<view class="g-item right" @click="na(index)">
						<image :src="goodsList[index + 1].image" mode="aspectFill"></image>
						<view class="t-box">
							<text class="title clamp">{{ goodsList[index + 1].title1 }}</text>
							<view class="price-box">
								<text class="price">￥{{ goodsList[index + 1].price }}</text>
								<text class="m-price">￥188</text>
							</view>
							<view class="pro-box">
								<view class="progress-box"><progress percent="72" activeColor="#fa436a" active stroke-width="6" /></view>
								<text>10人成团</text>
							</view>
						</view>
					</view>
				</swiper-item>
			</swiper>
		</view>
		<!-- 猜你喜欢 -->
		<view class="f-header m-t">
			<image src="/static/temp/h1.png"></image>
			<view class="tit-box">
				<text class="tit">猜你喜欢</text>
				<text class="tit2">良心推荐</text>
			</view>
		</view>
		<view class="guess-section">
			<view v-for="(item, index) in goodsList" :key="index" class="guess-item" @click="navToDetailPage(item)">
				<view class="image-wrapper"><image :src="item.image" mode="aspectFill"></image></view>
				<text class="title clamp">{{ item.title }}</text>
				<text class="price">￥{{ item.price }}</text>
			</view>
		</view>
		<view class="moreMsg">{{ moreMsg }}</view>
	</view>
</template>

<script>
import Api from '../../Api.js';
import uniSearchBar from '@/components/uni-search-bar/uni-search-bar.vue';
export default {
	data() {
		return {
			carouselList: [],
			goodsList: [],
			pageNum: 1, //加载更多页数
			moreMsg: '正在加载更多数据...' //触底提示语
		}
	},
	components: { uniSearchBar },
	onLoad() {
		this.carouselList = Api.carouselList;
		this.goodsList = Api.goodsList;
	},
	// 下拉刷新
	onPullDownRefresh() {
		this.pageNum=1;
		this.goodsList=Api.goodsList
	},
	//触底
	onReachBottom() {
		this.getMore();
	},
	methods: {
		na(index){
			let pid=index+2;
			console.log(pid)
			uni.navigateTo({
				url: `/pages/details/details?pid=${pid}`
			});
		},
		//跳转到详情页
		navToDetailPage(item) {
			let pid=item.pid;
			uni.navigateTo({
				url: `/pages/details/details?pid=${pid}`
			});
		},
		getMore() {
			setTimeout(() => {
				console.log(this.pageNum);
				if (this.pageNum > 3) {
					this.moreMsg = '没有更多数据了...';
					return;
				}
				uni.showNavigationBarLoading();
				let arr = this.goodsList;
				this.goodsList = this.goodsList.concat(arr);
				uni.hideNavigationBarLoading();
				this.pageNum++;
			}, 100);
		}
	}
};
</script>

<style lang="scss">
.content {
	display: flex;
	flex-direction: column;
	align-items: center;
	justify-content: center;
}
.search {
	width: 90%;
}
.banner {
	width: 100%;
	.swiper {
		width: 100%;
		height: 426rpx;
		.swiper-item {
			width: 100%;
			height: 100%;
			overflow: hidden;
			image {
				width: 100%;
				height: 100%;
			}
		}
	}
}
.cate-section {
	width: 100%;
	height: 180rpx;
	display: flex;
	justify-content: space-evenly;
	border-radius: 16rpx 16rpx 0 0;
	.cate-item {
		height: 100%;
		display: flex;
		flex-direction: column;
		align-items: center;
		font-size: 26rpx;
		color: #303133;
		margin-top: 20rpx;
		image {
			width: 100rpx;
			height: 100rpx;
			margin-bottom: 14rpx;
			border-radius: 50%;
			opacity: 0.7;
			box-shadow: 4rpx 4rpx 20rpx rgba(250, 67, 106, 0.3);
		}
	}
}
.ad-1 {
	width: 100%;
	height: 210rpx;
	margin-left: 30rpx;
	background: #fff;
	image {
		width: 100%;
		height: 100%;
	}
}
/* 秒杀专区 */
.seckill-section {
	width: 100%;
	padding: 4upx 30upx 24upx;
	background: #fff;
	.s-header {
		margin-left: 30rpx;
		display: flex;
		align-items: center;
		height: 92upx;
		line-height: 1;
		.s-img {
			width: 140upx;
			height: 30upx;
		}
		.tip {
			font-size: 28rpx;
			color: #909399;
			margin: 0 20upx 0 40upx;
		}
		.timer {
			display: inline-block;
			width: 40upx;
			height: 36upx;
			text-align: center;
			line-height: 36upx;
			margin-right: 14upx;
			font-size: 26rpx;
			color: #fff;
			border-radius: 2px;
			background: rgba(0, 0, 0, 0.8);
		}
	}
	.floor-list {
		white-space: nowrap;
		width: 100%;
		margin-left: 20rpx;
	}
	.scoll-wrapper {
		width: 100%;
		display: flex;
		align-items: flex-start;
	}
	.floor-item {
		width: 25%;
		font-size: 26rpx;
		color: #303133;
		line-height: 1.8;
		.clamp {
			overflow: hidden;
			text-overflow: ellipsis;
			white-space: nowrap;
			display: block;
		}

		image {
			width: 150upx;
			height: 150upx;
			border-radius: 6upx;
		}
		.price {
			color: #fa436a;
		}
	}
}

.f-header {
	display: flex;
	margin-left: 30rpx;
	width: 100%;
	align-items: center;
	height: 90upx;
	background: #fff;
	image {
		flex-shrink: 0;
		width: 80upx;
		height: 80upx;
		margin-right: 20upx;
	}
	.tit-box {
		flex: 1;
		display: flex;
		flex-direction: column;
	}
	.tit {
		font-size: 34rpx;
		color: green;
		line-height: 1.3;
	}
	.tit2 {
		font-size: 24rpx;
		color: #909399;
	}
}

/* 团购楼层 */
.group-section {
	width: 100%;
	background: #fff;
	flex: 1;
	.g-swiper {
		width: 100%;
		height: 650upx;
		padding-bottom: 30upx;
	}
	.g-swiper-item {
		width: 100%;
		display: flex;
	}
	.g-item {
		display: flex;
		flex-direction: column;
		overflow: hidden;
	}
	.left {
		flex: 1.2;
		margin-right: 24upx;
		.t-box {
			padding-top: 20upx;
		}
		image {
			width: 100%;
			height: 460upx;
			border-radius: 4px;
		}
	}
	.right {
		flex: 0.8;
		flex-direction: column-reverse;
		.t-box {
			padding-bottom: 20upx;
		}
		image {
			width: 100%;
			height: 460upx;
			border-radius: 4px;
		}
	}
	.t-box {
		height: 160upx;
		font-size: 30rpx;
		color: #303133;
	}
	.price {
		color: #fa436a;
	}
	.m-price {
		font-size: 26rpx;
		text-decoration: line-through;
		color: #909399;
		margin-left: 8upx;
	}
	.pro-box {
		display: flex;
		align-items: center;
		margin-top: 10rpx;
		font-size: 24rpx;
		color: 28rpx;
		padding-right: 10rpx;
		width: 86%;
	}
	.progress-box {
		flex: 1;
		border-radius: 10px;
		overflow: hidden;
		margin-right: 8upx;
	}
}
/* 猜你喜欢 */
.guess-section {
	display: flex;
	flex-wrap: wrap;
	padding: 0 30upx;
	background: #fff;
	.guess-item {
		display: flex;
		flex-direction: column;
		width: 48%;
		padding-bottom: 40upx;
		&:nth-child(2n + 1) {
			margin-right: 4%;
		}
		.image-wrapper {
			width: 100%;
			height: 330upx;
			border-radius: 3px;
			overflow: hidden;
			image {
				width: 100%;
				height: 100%;
				opacity: 1;
			}
		}
		.title {
			font-size: 32rpx;
			color: #303133;
			margin-top: 12rpx;
			overflow: hidden;
			text-overflow: ellipsis;
			white-space: nowrap;
			display: block;
		}
		.price {
			font-size: 32rpx;
			color: #fa436a;
			line-height: 1;
		}
	}
}
.moreMsg {
	width: 100%;
	height: 80rpx;
	text-align: center;
	line-height: 80rpx;
	color: #222;
}
</style>
